# -*- coding: utf-8 -*-
import sqlite3

conn = sqlite3.Connection("test.db")
print("Opened database successfully!")

c = conn.cursor()  # 获取游标
"""
# 创建数据表
sql = '''
    create table company (
        id int primary key not null ,
        name text not null ,
        age int not null ,
        addr char(50) ,
        salary real
    );
'''
c.execute(sql)  # 执行SQL

conn.commit()
print("数据写入成功!")

conn.close()
print("Database Closed!")
"""


# 插入数据
"""
sql1 = '''
    insert into company (id, name, age, addr, salary)
    values (1, '张三', '32', '石家庄', 6000);
'''
c.execute(sql1)

sql2 = '''
    insert into company (id, name, age, addr, salary)
    values (2, '李四', '22', 'Beijing', 8000);
'''
c.execute(sql2)

sql3 = '''
    insert into company (id, name, age, addr, salary)
    values (3, 'jason', '42', 'Beijing', 80000);
'''
c.execute(sql3)
conn.commit()
"""

# 查询数据
sql = '''
    select * from company;
'''
data = c.execute(sql)
print("========数据========")
print(data.fetchall())
c.close()
